from jsonpath import jsonpath
from pprint import pprint

my_dict = {'code': '1', 'msg': {'msg': "测试成功"}}
res = jsonpath(my_dict, "msg")
print(res)
print(type(res))
"""
结果：
[{'msg': '测试成功'}]
<class 'list'>
"""
print('------------------------------------')
my_dict = {
    "expensive": 10,
    "store": {
        "bicycle": {
            "color": "red",
            "price": 19.95
        },
        "book": [
            {
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century",
                "price": 8.95
            },
            {
                "category": "fiction",
                "author": "J. R. R. Tolkien",
                "title": "The Lord of the Rings",
                "isbn": "0-395-19395-8",
                "price": 22.99
            }
        ]
    }
}
res = jsonpath(my_dict, '$.store.book[?(@.price<25)]')
pprint(res)
"""
结果：
[{'author': 'Nigel Rees',
  'category': 'reference',
  'price': 8.95,
  'title': 'Sayings of the Century'}]
"""
print('------------------------------------')
res = jsonpath(my_dict, '$.store[book,bicycle]')
pprint(res)
"""
结果：
[[{'author': 'Nigel Rees',
   'category': 'reference',
   'price': 8.95,
   'title': 'Sayings of the Century'},
  {'author': 'J. R. R. Tolkien',
   'category': 'fiction',
   'isbn': '0-395-19395-8',
   'price': 22.99,
   'title': 'The Lord of the Rings'}],
 {'color': 'red', 'price': 19.95}]
"""
print('------------------------------------')
res = jsonpath(my_dict, '$..price')
pprint(res)
"""
结果：
[8.95, 22.99, 19.95]
"""
print('------------------------------------')
res = jsonpath(my_dict, '.')
pprint(res)
"""
结果：
[8.95, 22.99, 19.95]
"""
